package org.jcommon.com.util.system;

import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.jcommon.com.util.config.ConfigLoader;
/**
 * 
 * @author LeoLee<leo.li@protel.com.hk>
 *
 */
public class SystemConfig implements SystemConfigMBean {
	private static final SystemConfig instance = new SystemConfig();
	private static Logger logger = Logger.getLogger(SystemConfig.class);
	
	private long version;
	
	private Map<String,String> system_object;

	private int init_threads = 60;
	
	private String htmladapter;
	
	private String rmiadapter;
	
	private String mbean_server = "default";
	
	private List<String> ShareObject;
	
	private InputStream init_file_is;
	
	public static SystemConfig instance(){	
		return  instance ;
	}
	
	public void setSystem_object(Map<String,String> system_object) {
		this.system_object = system_object;
	}

	public Map<String,String> getSystem_object() {
		return system_object;
	}

	public void setInit_threads(int init_threads) {
		this.init_threads = init_threads;
	}

	public int getInit_threads() {
		return init_threads;
	}

	public void setConfigUrl(InputStream init_file_is) {
		this.init_file_is = init_file_is; 
	}
	
	@Override
	public void reloadConfig() {
		// TODO Auto-generated method stub
		if(init_file_is==null){
			logger.info("input Stream can not be null");
			return;
		}
		try {
			ConfigLoader.loadConf4xml(init_file_is, this);
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			logger.error("",e1);
			return;
		}
	}

	public void setHtmladapter(String htmladapter) {
		this.htmladapter = htmladapter;
	}

	public String getHtmladapter() {
		return htmladapter;
	}

	@Override
	public void saveConfig() {
		// TODO Auto-generated method stub
		if(init_file_is==null){
			logger.info("input Stream can not be null");
			return;
		}
	}

	public void setMbean_server(String mbean_server) {
		this.mbean_server = mbean_server;
	}

	public String getMbean_server() {
		return mbean_server;
	}

	public void setRmiadapter(String rmiadapter) {
		this.rmiadapter = rmiadapter;
	}

	public String getRmiadapter() {
		return rmiadapter;
	}

	public void setShareObject(List<String> ShareObject) {
		this.ShareObject = ShareObject;
	}

	public List<String> getShareObject() {
		return ShareObject;
	}

	@Override
	public void reStart() {
		// TODO Auto-generated method stub
		SystemManager.instance().restart();
	}

	public void setVersion(long version) {
		this.version = version;
	}

	public long getVersion() {
		return version;
	}
}
